package com.eversec.view.frame;

import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;

import com.eversec.util.resource.ResourceUtils;
import com.eversec.view.menu.IdcMenuBar;
import com.eversec.view.panel.FileCheckPanel;
import com.eversec.view.panel.FileEncrypationPanel;
import com.eversec.view.panel.TextEncryptionPanel;

/**
 * 主界面Frame
 * @author Administrator
 *
 */
public class MainFrame extends JFrame {

	private static final long serialVersionUID = 7950787122934132602L;

	public MainFrame() throws HeadlessException {
		setLookAndFeel();
		initComponent();
		showUI();
	}

	/**
	 * 设置界面风格
	 */
	private void setLookAndFeel() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 初始化组件
	 */
	private void initComponent() {
		setLayout(new BorderLayout());
		
		setJMenuBar(new IdcMenuBar());
		
		JTabbedPane detecteTabPane = new JTabbedPane();
		detecteTabPane.add("文本解密", new TextEncryptionPanel());
		detecteTabPane.add("文件解密", new FileEncrypationPanel());
		detecteTabPane.add("文件校对", new FileCheckPanel());
		
		add(detecteTabPane, BorderLayout.CENTER);
	}

	/**
	 * 设置界面属性
	 */
	private void showUI() {
		setTitle("IDC检测工具");
		setSize(800, 680);

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// frame初始化到屏幕中央
		int pw = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
		int w = this.getWidth();
		int ph = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
		int h = this.getHeight();
		setLocation((pw - w) / 2, (ph - h) / 2);

		if (ResourceUtils.TITLE_URL != null) {
			setIconImage(Toolkit.getDefaultToolkit().getImage(ResourceUtils.TITLE_URL));
		}
//		setVisible(true);
	}

}
